<?php
class BasePaths {
	public $server, $public;
	private $base;
	public function __construct ($base) {
		// server absolute path
		$server = $this->removeBlanksInArray(explode('/',  $this->windowsToUnixPaths($base)), false);
		array_pop($server);
		$server = '/'.implode('/',$server).'/';
		
		// public, visual path
		$docRoot = $this->windowsToUnixPaths($_SERVER['DOCUMENT_ROOT']);
		if(substr_count($server, $docRoot) < 1) {
			$docRoot = explode('/', trim($docRoot,'/'));
			unset($docRoot[0]);
			$docRoot = '/'.implode('/', $docRoot);
		}
		$public = $this->removeBlanksInArray(explode($docRoot, $server), false);
		
		// assign
		$this->server = $server;
		$this->public = $public[0];
	}
	public function windowsServer() {
		return $this->base;
	}
	public function windowsToUnixPaths ($str) {
		$str = preg_replace('/[a-zA-Z]:\\\/', '\\', $str);
		$str = str_replace("\\",'/', $str);
		return $str;
	}
	protected function removeBlanksInArray ($arr, $keep = true) {
		foreach($arr as $key => $value) {
			if(!empty($value)) {
				if($keep == true)
					$newArr[$key] = $value;
				else
					$newArr[] = $value;
			}
		}
		return $newArr;
	}
}
?>